package com.weixin.engine.controller;

import com.weixin.common.core.doman.Result;
import com.weixin.engine.models.pojo.LmToken;
import com.weixin.engine.models.service.ILmTokenService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 前端控制器
 *
 * @author wangchunhui
 * @date 2023-06-06
 */
@RestController
@RequestMapping("/manage/lm-token")
public class LmTokenController {

    @Resource
    private ILmTokenService lmTokenService;

    /**
     * 新增LmToken
     */
    @PostMapping
    public Result add(@RequestBody LmToken lmToken) {
        boolean flag = lmTokenService.save(lmToken);
        if (!flag) {
            return Result.FAIL();
        }
        return Result.SUCCESS();
    }

    /**
     * 删除LmToken
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id) {
        boolean flag = lmTokenService.removeById(id);
        if (!flag) {
            return Result.FAIL();
        }
        return Result.SUCCESS();
    }

    /**
     * 更新LmToken
     */
    @PutMapping
    public Result update(@RequestBody LmToken lmToken) {
        boolean flag = lmTokenService.updateById(lmToken);
        if (!flag) {
            return Result.FAIL();
        }
        return Result.SUCCESS();
    }

    /**
     * LmToken详情
     */
    @GetMapping("/{id}")
    public Result detail(@PathVariable String id) {
        LmToken lmToken = lmTokenService.getById(id);
        if (lmToken == null) {
            return Result.FAIL();
        }
        return Result.SUCCESS(lmToken);
    }

    /**
     * LmToken分页列表
     *
     * @param pageNum  页码
     * @param pageSize 每页记录数
     */
    @PostMapping("/page")
    public Result page(@RequestBody LmToken lmToken, @RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.SUCCESS();
    }
}
